package org.manusoft.refill.service;

import java.util.List;
import java.util.Map;

import org.manusoft.refill.dao.VehicleDAO;
import org.manusoft.refill.domain.TRefillingDetailsRf;
import org.manusoft.refill.domain.TVehicleDetailsRf;
import org.primefaces.model.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("vehicleService")
public class VehicleServiceImpl implements VehicleService{

	@Autowired
	private VehicleDAO vehicleDAO;
	
		
	@Transactional
	public void createNew(TVehicleDetailsRf vehicleDetailsRf) {
		vehicleDAO.makePersistent(vehicleDetailsRf);
	}

	@Transactional(readOnly=true)
	public List<TVehicleDetailsRf> findAll() {
		return vehicleDAO.findAll();
	}
    

	
	@Transactional
	public void update(TVehicleDetailsRf vehicleDetailsRf) {
		vehicleDAO.makePersistent(vehicleDetailsRf);
	}
	
	@Transactional
	public void remove(TVehicleDetailsRf vehicleDetailsRf) {
		vehicleDAO.remove(vehicleDetailsRf);
	}

	@Transactional(readOnly=true)
	public TVehicleDetailsRf findById(Integer id,boolean isLock) {
		return vehicleDAO.findById(id,isLock);
	}
	
	@Transactional(readOnly=true)
	public TVehicleDetailsRf findByRegNum(String name) {
		return vehicleDAO.findByRegNum(name);
	}
	
	@Override
	@Transactional
	public TVehicleDetailsRf createUpdateVehicle(
			TVehicleDetailsRf vehicleDetailsRf) {
		return vehicleDAO.makePersistent(vehicleDetailsRf);
	}

	@Override
	public void delete(TVehicleDetailsRf vehicleDetailsRf) {
		vehicleDAO.remove(vehicleDetailsRf);
	}
	
    @Transactional(readOnly=true)
    public List<TVehicleDetailsRf> loadLazy(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
        return vehicleDAO.loadLazy(first, pageSize, sortField, sortOrder == SortOrder.ASCENDING ? "asc" : sortOrder == SortOrder.DESCENDING ? "desc" : null, filters);
    }
    
    @Transactional(readOnly=true)
	public Long getRowCount(Map<String, String> filters) {
		return vehicleDAO.getRowCount(filters);
	}
    @Transactional(readOnly=true)
    public List<TVehicleDetailsRf> findByRegNumAutoComplete(String regNum){
    	return vehicleDAO.findByRegNumAutoComplete(regNum);
    }
}